from flask import Flask,request,render_template

from wtforms import Form,StringField
from wtforms.validators import Length,EqualTo

app = Flask(__name__)

@app.route('/')
def index():
    return 'Hello'

class RegisterForm(Form):
    uname = StringField(validators=[Length(min=2,max=10,message='用户名长度是2到10之间')])
    pwd = StringField(validators=[Length(min=2,max=10)])
    pwd2 = StringField(validators=[Length(min=2,max=10),EqualTo('pwd',message='两次密码不一致')])



@app.route('/register/',methods=['GET','POST'])
def register():
    if request.method == 'GET':
        return render_template('register.html')
    else:
        form = RegisterForm(request.form)
        if form.validate():
            return '验证成功'
        else:
            return f'验证失败{form.errors}'

if __name__ == '__main__':
    app.run(debug=True)